import 'package:flutter/material.dart';
import 'package:flutter_crud_test_amir_rabbani/core/widgets/base_getview.dart';
import 'package:flutter_crud_test_amir_rabbani/core/widgets/button/primary_button.dart';
import 'package:flutter_crud_test_amir_rabbani/core/widgets/input/date_input.dart';
import 'package:flutter_crud_test_amir_rabbani/core/widgets/input/input.dart';
import 'package:flutter_crud_test_amir_rabbani/peresenter/crud/controller/add_customer_controller.dart';
import 'package:get/get.dart';

class AddCustomerPage extends BaseGetView<AddCustomerController> {
  AddCustomerPage({super.key});

  @override
  Widget buildState(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Obx(() =>
            Text('${controller.isUpdate.value ? 'Edit' : 'Add'} Customer')),
      ),
      resizeToAvoidBottomInset: true,
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          child: Column(
            children: [
              Row(
                children: [
                  Expanded(
                      child: Input(
                    hint: al.firstName,
                    controller: controller.firstName,
                  )),
                  SizedBox(width: 10),
                  Expanded(
                      child: Input(
                    hint: al.lastName,
                    controller: controller.lastName,
                  )),
                ],
              ),
              SizedBox(height: 10),
              Row(
                children: [
                  Expanded(
                      child: Input(
                    hint: al.email,
                    controller: controller.email,
                  )),
                  SizedBox(width: 10),
                  Expanded(
                      child: Input(
                    hint: al.phone,
                    controller: controller.phoneNumber,
                  )),
                ],
              ),
              SizedBox(height: 10),
              Row(
                children: [
                  Expanded(
                      child: Input(
                    hint: al.bank,
                    controller: controller.bankAccountNumber,
                  )),
                  SizedBox(width: 10),
                  Expanded(
                      child: Obx(() => DateInput(
                            value: controller.birthDate.value,
                            onSubmitted: (date) {
                              controller.birthDate.value = date;
                            },
                            hint: al.birthDate,
                          ))),
                ],
              ),
              SizedBox(height: 10),
              Obx(() => PrimaryButton(
                  controller.isUpdate.value ? al.edit : al.submit,
                  controller.isUpdate.value
                      ? controller.edit
                      : controller.create))
            ],
          ),
        ),
      ),
    );
  }
}
